<div class="container-fluid">
  <div class="row">
    <div class="col-md-9">
      <div class="doc-item">
        <h1>GRR API</h1>
      </div>

      <p>
        Below is the list of HTTP API calls that the GRR Admin UI can handle.
        For every supported route you'll find a list of supported query
        parameters (if any). These parameters are passed either as URL query
        parameters or as parts of URL path.<br/>
        For example:
      </p>
      <p>
        <samp>/api/hunts?<strong>offset=100&amp;count=20</strong></samp><br>
      </p>

      <br/>
      <h4>Permissions</h4>
      <p>
        If special permissions are required to access certain resources,
        &quot;reason&quot; query parameter may be specified.
        For example:</p>
      <p>
        <samp>/api/aff4/C.123456789abcdef1/analysis/AnalyzeClientMemory/myusername-1435178456.2?<strong>reason=InvestigationID+1234</strong></samp>
      </p>

      <br/>
      <h4>Type information</h4>
      <p>
        GRR API responses usually contain richly typed data. If you don't need the type information, you can strip it from any response by setting "strip_type_info" flag. For example:
      </p>
      <p>
        <samp>/api/hunts?offset=100&amp;count=20&amp;<strong>strip_type_info=1</strong></samp><br>
      </p>

      <h4>XSSI protection</h4>
      <p>
        To prevent against Cross Site Script Inclusion (XSSI) attacks, the JSON response body starts with a magic prefix line that must be stripped before feeding the rest of the response body to a JSON parser:
      </p>
      <p>
        <samp>)]}'<br>[ ... valid JSON ... ]</samp><br>
      </p>
      <br/>

      <div class="panel panel-default doc-item-category"
           ng-repeat="category in ::controller.categories">

        <div class="panel-heading" id="docs-category-{$ $index $}">
          <h2>{$ category $}</h2>
        </div>

        <div class="panel-body" grr-on-scroll-into-view="controller.visibleCategory = category">
          <div class="doc-item"
               ng-repeat="apiMethod in ::controller.apiMethodsByCategory[category]">
            <p class="lead">
              {$ ::apiMethod.http_methods.join(', ') $}
              <grr-api-route value="::apiMethod.http_route"></grr-api-route>
            </p>

            <grr-api-description value="::apiMethod.doc"></grr-api-description>
            <grr-api-query-spec args-type="::apiMethod.args_type_descriptor.name"></grr-api-query-spec>

            <div ng-if="controller.examplesByMethod[apiMethod.name].length > 0">
              <h4>Examples:</h4>

              <table class="example table table-condensed"
                     ng-repeat="example in ::controller.examplesByMethod[apiMethod.name]">
                <thead>
                  <th>
                    <grr-api-route value="::example.url"></grr-api-route>

                    <div class="pull-right" ng-if="::example.type_stripped_response !== undefined">
                      <input ng-model="example.showTypeStripped" type="checkbox">
                        Show type-stripped response
                      </input>
                    </div>

                    <div class="request-payload" ng-if="example.request_payload">
                      <span class="method-label">{$ ::apiMethod.http_methods.join(', ') $} body:</span>
                      <div class="json pre-scrollable">{$ ::example.request_payload | json:2 $}</div>
                    </div>
                  </th>
                </thead>
                <tbody>
                  <tr>
                    <td>
                      <div class="json pre-scrollable" ng-if="!example.showTypeStripped">{$ ::example.response | json:2 $}</div>
                      <div class="json pre-scrollable" ng-if="example.showTypeStripped">{$ ::example.type_stripped_response | json:2 $}</div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>

          </div>
        </div>

      </div>

    </div>
    <div class="col-md-3 vertically-padded">

      <div class="list-group doc-toc">
        <a ng-class="{'active': controller.visibleCategory == category}"
           ng-repeat="category in controller.categories" class="list-group-item"
           ng-click="controller.onCategoryLinkClick(category)">
          {$ category $}
        </a>
      </ul>
    </div>
  </div>  <!-- div class=row -->
</div>  <!-- div class=container-fluid -->
